package 链表;

import common.ListNode;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

/**
 * @author tmh
 * @date 2024/11/22 18:42
 * @description
 */
public class T160相交链表 {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        Set<ListNode> set = new LinkedHashSet<>();
        while (headA != null) {
            set.add(headA);
            headA = headA.next;
        }
        while (headB != null) {
            if (set.contains(headB)) {
                return headB;
            }
            headB = headB.next;
        }
        return null;
    }
}
